
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xsl

package com.dps.zain.struts.action;



import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.broadvision.web.servlet.SessionVisitor;
import com.dps.dao.channel.ChannelDao;

/** 
 * MyEclipse Struts
 * Creation date: 04-22-2007
 * 
 * XDoclet definition:
 * @struts:action validate="true"
 * @struts:action-forward name="viewChannels" path="/listChannels.jsp"
 */
public class ViewChannelAction extends Action {
	// --------------------------------------------------------- Instance Variables

	// --------------------------------------------------------- Methods

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response) {

	    System.out.println("ENTERING into class: "+ this.getClass());
        SessionVisitor sessionVisitor = SessionVisitor.getInstance(request.getSession());
        String serviceID="";
        
        if(sessionVisitor != null && sessionVisitor.getServiceId()!=0)
        {
            serviceID = new Integer (sessionVisitor.getServiceId()).toString();
            System.out.println("serviceID got from request: "+ serviceID);
        } else
        {
            System.out.println("SessionVisitor is null Or serviceID from request is 0. System cannot proceed");
            return mapping.findForward("error");
        }
        ChannelDao channel = new ChannelDao(sessionVisitor);
        List channels = null;
     
        if(request.getAttribute("channelId") != null){		
			channels = channel.getSubChannels((String)request.getAttribute("channelId"));
		}
		else{
			System.out.println("channelId from request is null. Therefore getting all root channels");
			channels = channel.getRootChannels(); 
		   }
		request.setAttribute("channels",channels);
		return mapping.findForward("viewChannels");
	}

}
